<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>添加权限-目的地运营集团数据管理平台</title>
<include file="Include:style" />
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text">权限 > 添加权限</div>
	</div>
	<div id="content">
		<form action="__APP__/System/permissions_list_add" method="post" name="permission_validate" id="permission_validate" novalidate="novalidate" >
			<input type="hidden" name="action" value="add">
			<div class="form-main">
				<div class="form-title">添加权限</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>权限类型</div>
					<div class="input-item">
						<select name="type" class="form-control" autocomplete="off">
							<option value="-10">请选择</option>
							<foreach name="types" item="vo">
							<option value="{$vo['type']}">{$vo['type']}</option>
							</foreach>
						</select>
						<span class="error-item">必填项</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>权限编号</div>
					<div class="input-item">
						<input name="name_num" type="text" class="form-control" autocomplete="off">
						<span class="error-item">必填项</span>
						<span class="error-item">不能含有空格</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>权限名称</div>
					<div class="input-item">
						<select name="name_cn" class="w200" autocomplete="off">
							<option value="-10">请先选择权限类型</option>
						</select>
						<input name="name_cn_text" type="text" class="form-control" placeholder="新增权限名称" autocomplete="off">
						<select name="name_detail" class="w200" autocomplete="off">
							<option value="-10">无</option>
							<foreach name="name_detail_list" item="vo">
								<option value="{$vo['name1']}">{$vo['name2']}</option>
							</foreach>
						</select>
						<span class="error-item">必填项</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label">权限备注</div>
					<div class="input-item">
						<input name="name_remark" id="name_remark" type="text" class="form-control" autocomplete="off">
					</div>
				</div>
			</div>
			<div class="form-btn-item"><button class="btn sub" type="submit">提交</button><button class="btn btn-default goback" type="button">返回</button></div>
		</form>
	</div>
</div>
<include file="Include:javascript" />
<script type="text/javascript">
$(function(){
	//权限类型&权限名称
	$("[name='type']").on("change",function(){
		var type = $(this).val();
		$(this).nextAll(".error-item").hide();
		if(type!=-10){
			$.ajax({
				type:"POST",
				asnyc:true,
				dataType:"json",
				data:{"type":type},
				url:"__APP__/System/get_name_list",
				success:function(data){
					var option = "<option value='-10' selected>请选择</option>";
					for(var x in data){
						option += "<option value="+data[x].name_cn+">"+data[x].name_cn+"</option>";
					}
					$("[name='name_cn']").html(option).trigger("change");
				}
			});
		}else{
			$("[name='name_cn']").html("<option value='-10' selected>请先选择权限类型</option>").trigger("change");
		}
	});
	
	$("[name='name_cn']").on("change",function(){
		var name_cn = $(this).val(),
			name_cn_text = $("[name='name_cn_text']");
		$(this).nextAll(".error-item").hide();
		if(name_cn==-10){
			name_cn_text.show();
		}else{
			name_cn_text.hide().val("");
		}
	});
	
	$(".sub").on("click",function(){
		var tag = false;
		$("[name='type']").each(function(){
			if($(this).val()==-10){
				$(this).nextAll(".error-item").show();
				tag = true;
			}
		});
		$("[name='name_num']").each(function(){
			var val = $(this).val();
			if(val==""){
				$(this).next(".error-item").show();
				tag = true;
			}else if(/\s/.test(val)){
				$(this).nextAll(".error-item").eq(1).show();
				tag = true;
			}
		});
		$("[name='name_cn_text']").each(function(){
			var val = $(this).val(),
				name_cn = $("[name='name_cn']").val();
			if(name_cn==-10 && (val=="" || /^\s+$/.test(val))){
				$(this).nextAll(".error-item").show();
				tag = true;
			}
		});
		
		if(tag){
			return false;
		}
	});
	//取消错误提示
	$("[name='name_num'],[name='name_cn_text']").on("focus",function(){
		$(this).nextAll(".error-item").hide();
	});
});
</script>
</body>
</html>